package com.code.day11;

public class Test01 {
    public static void main(String[] args) {
        USB usb = method(); //USB usb = new Mouse();
        usb.open(); //mouse.open()


        method(new USB() {
            @Override
            public void open() {
                System.out.println("我好想睡觉");
            }
        });
        USB usb1 = method1();
        usb1.open();
    }

    /**
     * 接口类型作为方法返回值返回,我们应该返回的是USB的实现类对象
     * @return
     */
    public static USB method(){
        class Mouse implements USB{
            @Override
            public void open() {
                System.out.println("USB开启");
            }
        }
        return new Mouse();
    }

    public static  void method(USB usb){
        usb.open();
    }

    public static USB method1(){
        return new USB() {
            @Override
            public void open() {
                System.out.println("我好想睡觉");
            }
        };
              /*USB usb = new USB() {
            @Override
            public void open() {
                System.out.println("usb打开了");
            }
        };

        return usb;*/
    }
}
